// 测试连接：http://poj.org/problem?id=2449
// 帖子讲解：https://www.cnblogs.com/dx123/p/17500173.html

#include <cstdio>
#include <queue>
#include <cstring>

using namespace std;

const int MAXN = 1010;
const int MAXM = 200010;
int head[MAXN];
int rhead[MAXN];
int to[MAXM];
int next[MAXM];
int weight[MAXM];
int cnt = 1;
int n, m, S, T, K;
int dist[MAXN]; // 原点到任一点的最短距离
bool visited[MAXN];
int count[MAXN]; 

struct Node
{
    int s, v, d; // s原点到终点的预估距离排序，v到达的点，d实际的距离

    bool operator<(const Node& other) const
    {
        return s > other.s; // 这样写的目的是让标准库的大堆变成小堆
    }
};

void addEdge(int h[], int u, int v, int w)
{
    ::next[cnt] = h[u];
    to[cnt] = v;
    weight[cnt] = w;
    h[u] = cnt++;
}

// 反图跑 Dijkstra 算法，算出预估距离
void dijkstra()
{
    memset(dist, 0x3f, sizeof dist);
    dist[T] = 0;

    priority_queue<pair<int, int>> heap;
    heap.push(make_pair(0, T));
    while(!heap.empty())
    {
        pair<int, int> t = heap.top();
        heap.pop();
        int u = t.second;
        if(visited[u]) continue;
        // 第一次出队则表明，原点到该点的最短距离已经求出
        visited[u] = true; 
        for(int ei = rhead[u]; ei; ei = ::next[ei])
        {
            int v = to[ei];
            if(dist[v] > dist[u] + weight[ei])
            {
                dist[v] = dist[u] + weight[ei]; // 预估函数
                heap.push(make_pair(-dist[v], v));
            }
        }
    }
}

int aStar()
{
    priority_queue<Node> heap;
    Node a = {dist[S], S, 0};
    heap.push(a);
    while(!heap.empty())
    {
        Node t = heap.top();
        heap.pop();
        int u = t.v;
        ++::count[u]; // 记录出队次数
        if(::count[T] == K) return t.d; // 边界
        for(int ei = head[u]; ei; ei = ::next[ei])
        {
            int v = to[ei], d = t.d + weight[ei];
            if(::count[v] < K)
            {
                Node a = {d + dist[v], v, d};
                heap.push(a);
            }
        } 
    }
    return -1;
}

int main()
{
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= m; ++i)
    {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        addEdge(head, u, v, w);
        addEdge(rhead, v, u, w);
    }

    scanf("%d%d%d", &S, &T, &K);
    if(S == T) ++K; // 重合点，0 是第一条短路
    dijkstra();
    printf("%d\n", aStar());

    return 0;
}